package com.zikao.article.controller;

import java.util.*;

import com.zikao.common.vo.TableListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.zikao.article.entity.TagEntity;
import com.zikao.article.service.TagService;
import com.zikao.common.utils.PageUtils;
import com.zikao.common.utils.R;

/**
 * @author likaisheng
 * @email 1805318928@qq.com
 * @date 2021-02-21 10:55:38
 */
@Controller
@RequestMapping("article/tag")
public class TagController {
    @Autowired
    private TagService tagService;

    /**
     * 查出所有标签
     */
    @RequestMapping("/all")
    @ResponseBody
    public R all(@RequestParam Map<String, Object> params){
        List<TagEntity> all = tagService.selectByMap(params);
        return R.ok().put("items", all);
    }

    @RequestMapping("/listForLayUI")
    @ResponseBody
    public TableListVo listForLayUI(@RequestParam Map<String, Object> params){
        PageUtils page = tagService.queryPage(params);
        TableListVo<TagEntity> tableListVo = new TableListVo();

        tableListVo.setCode(0);
        tableListVo.setMsg("");
        tableListVo.setCount(page.getTotalCount());

        List<TagEntity> tagList = (List<TagEntity>) page.getList();
        tableListVo.setData(tagList);
        return tableListVo;
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tagService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @ResponseBody
    public R info(@PathVariable("id") Long id){
		TagEntity tag = tagService.getById(id);

        return R.ok().put("tag", tag);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @ResponseBody
    public R save(@RequestBody TagEntity tag){
		tagService.save(tag);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @ResponseBody
    public R update(@RequestBody TagEntity tag){
		tagService.updateById(tag);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @ResponseBody
    public R delete(@RequestBody Long[] ids){
		tagService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
